export default {
  string: `@Get('/sqli/string/queryUser')
async sqliString(@Query('username') username: string) {
  const spliceSQL = \`SELECT * FROM USER WHERE username='\${username}'\`;
  return await this.userService.queryUserBySQL(spliceSQL).catch(() => {
    throw new ParamsLack();
  });
}
// --------------------------------------------------------------------------
const Vulnerable: React.FC = () => {
  const [form] = Form.useForm();
  const [dataSource, setDataSource] = useState<any[]>([]);
  const { t } = useTranslation();

  // 获取用户信息
  const { run, loading } = useRequest(
    async () => {
      const params = form.getFieldsValue();
      await queryUserByUsername(params).then(res => setDataSource(res));
    },
    { manual: true },
  );

  return (
    <>
      <Title italic level={4}>
        {t('sqli.string.title')}
      </Title>
      <Form form={form}>
        <Input.Group compact>
          <Form.Item name="username" label={t('userid')} labelAlign="left" labelCol={{ span: 8 }}>
            <Input />
          </Form.Item>
          <Button onClick={run}>{t('confirm')}</Button>
        </Input.Group>
      </Form>
      <Title italic level={4}>
        {t('userinfo')}
      </Title>
      <Spin spinning={loading}>
        {dataSource.length === 0 && (
          <Empty
            style={{ color: 'var(--empty-font)' }}
            image={Empty.PRESENTED_IMAGE_SIMPLE}
            description={t('empty')}
          />
        )}
        {dataSource.map((m, idx) => (
          <Descriptions column={4} key={idx}>
            <Descriptions.Item label="id">{m.id}</Descriptions.Item>
            <Descriptions.Item label="username">{m.username}</Descriptions.Item>
            <Descriptions.Item label="create_time">
              {moment(m.create_time).format('YYYY-MM-DD HH:mm:ss')}
            </Descriptions.Item>
            <Descriptions.Item label="update_time">
              {moment(m.update_time).format('YYYY-MM-DD HH:mm:ss')}
            </Descriptions.Item>
          </Descriptions>
        ))}
      </Spin>
    </>
  );
};
`,
  number: `@Get('/sqli/number/queryUser')
async sqliNumber(@Query('id') id: string) {
  const spliceSQL = \`SELECT * FROM USER WHERE id=\${id}\`;
  return await this.userService.queryUserBySQL(spliceSQL).catch(() => {
    throw new ParamsLack();
  });
}
// --------------------------------------------------------------------------
const Vulnerable: React.FC = () => {
  const [form] = Form.useForm();
  const [dataSource, setDataSource] = useState<any[]>([]);
  const { t } = useTranslation();

  // 获取用户信息
  const { run, loading } = useRequest(
    async () => {
      const params = form.getFieldsValue();
      await queryUserById(params).then(res => setDataSource(res));
    },
    { manual: true },
  );

  return (
    <>
      <Title italic level={4}>
        {t('sqli.string.title')}
      </Title>
      <Form form={form}>
        <Input.Group compact>
          <Form.Item name="id" label={t('userid')} labelAlign="left" labelCol={{ span: 8 }}>
            <Input />
          </Form.Item>
          <Button onClick={run}>{t('confirm')}</Button>
        </Input.Group>
      </Form>
      <Title italic level={4}>
        {t('userinfo')}
      </Title>
      <Spin spinning={loading}>
        {dataSource.length === 0 && (
          <Empty
            style={{ color: 'var(--empty-font)' }}
            image={Empty.PRESENTED_IMAGE_SIMPLE}
            description={t('empty')}
          />
        )}
        {dataSource.map((m, idx) => (
          <Descriptions column={4} key={idx}>
            <Descriptions.Item label="id">{m.id}</Descriptions.Item>
            <Descriptions.Item label="username">{m.username}</Descriptions.Item>
            <Descriptions.Item label="create_time">
              {moment(m.create_time).format('YYYY-MM-DD HH:mm:ss')}
            </Descriptions.Item>
            <Descriptions.Item label="update_time">
              {moment(m.update_time).format('YYYY-MM-DD HH:mm:ss')}
            </Descriptions.Item>
          </Descriptions>
        ))}
      </Spin>
    </>
  );
};`,
};
